package com.example.demo.leetcode.classics150;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _48汇总区间
 * @description
 * @date 2023/07/23 10:17
 * <p>
 * ******************************************************
 */
public class _48汇总区间 {

    public List<String> summaryRanges(int[] nums) {
        List<String> res = new LinkedList<>();

        int start = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i == nums.length - 1 || nums[i + 1] - nums[i] != 1) {
                if (i == start) {
                    res.add(String.valueOf(nums[i]));
                } else {
                    res.add(nums[start] + "->" + nums[i]);
                }
                start = i + 1;
            }
        }

        return res;

    }

}
